/*
https://leetcode.cn/problems/next-greater-element-i/
*/
class Solution {
public:
    vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {
        unordered_map<int,int>mp;
        vector<int> ans(nums1.size(), -1);
        stack<int> st;
        for (int i = nums2.size() - 1; i >= 0; --i) {
            int x = nums2[i];
            while (!st.empty() && x >= st.top()) {
                st.pop();
            }
            if (!st.empty())      mp[x]=st.top();
            st.push(x);
        }
        for(int i=0;i<nums1.size();++i){
            ans[i]=mp[nums1[i]];
            if(mp[nums1[i]]==0) ans[i]=-1;

        }
        return ans;

    }
};